package fr.umlv.m2.jee.pmlv.persistence.note.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import fr.umlv.m2.jee.pmlv.framework.dao.hibernate.AbstractHibernateDAO;
import fr.umlv.m2.jee.pmlv.persistence.note.UserThemeNote;

@Repository("hibernateUserThemeNoteDAO")
public class HibernateUserThemeNoteDAO 
	extends AbstractHibernateDAO<Long, UserThemeNote> implements IUserThemeNoteDAO {

    @Override
    public List<UserThemeNote> findByUserAndByYear(String uid, int year) {
            String query = "from UserThemeNote as note where note.uid = '"+uid+"' and note.theme.year="+year;
            return findByQuery(query);

    }

    @Override
    public UserThemeNote findByUserAndThemeAndByYear(String uid, Long theme, int year) {
            String query = "from UserThemeNote as note where note.uid= '"+uid+"' and note.theme.id ="+theme+" and note.theme.year="+year;
            List<UserThemeNote> tmp = findByQuery(query);
            return ( tmp.isEmpty() ? null : tmp.get(0));
    }

    @Override
    public List<UserThemeNote> findByThemeAndByYear(Long theme, int year) {
            String query = "from UserThemeNote as note where note.theme.id ="+theme+" and note.theme.year="+year;
            return findByQuery(query);
    }

    @Override
    public List<UserThemeNote> findByUserAndSubjectAndByYear(String uid, Long subject, int year) {
        String query = "from UserThemeNote as note where note.theme.subject.id ="+subject+" and note.theme.year="+year+" and note.uid='"+uid+"'";
	return findByQuery(query);
    }
}
